using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SenFangKaoHe_MVC.Models;
using SenFangKaoHe_MVC.Models.Entity;
using SenFangKaoHe_MVC.Models.ViewModel;
using SenFangKaoHe_MVC.Services;
using SqlSugar;

namespace SenFangKaoHe_MVC.Controllers
{
    public class HomeController : Controller
    {
        private readonly SqlSugarClient db;

        public HomeController(SqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<IActionResult> Index()
        {
            return View();
        }

        public async Task<List<kaohe>> getWeiKaoHe(string xm)
        {
            List<kaohe> khs = await new KaoShiServices(db).getWeiKaoHes(xm);
            return khs;
        }

        public async Task<List<kaohe>> getKaoHe(string xm)
        {
            List<kaohe> khs = await new KaoShiServices(db).getKaoHes(xm);
            return khs;
        }

        public async Task<List<kaohe>> getKaoHes()
        {
            List<kaohe> khs = await new KaoShiServices(db).getKaoHes();
            return khs;
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
